/*
 * @Author: your name
 * @Date: 2022-11-04 19:07:22
 * @LastEditTime: 2023-09-05 18:43:26
 * @LastEditors: DESKTOP-4QFD9PO
 * @Description: In User Settings Edit
 * @FilePath: \ClothMes\vite.config.ts
 */
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import * as path from 'path'
import { defineConfig } from 'vite'
import * as dotenv from 'dotenv'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from "unplugin-auto-import/vite"
// 在正式打包的时候，可以把这两行代码放开
// import Components from 'unplugin-vue-components/vite'
// import { ArcoResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig(({ mode }) => {
  const dotenvConfig = dotenv.config({ path: `./.env.${mode}` })
  const dotenvObj: any = dotenvConfig.parsed
  return {
    base: dotenvObj.BUILD_PATH,
    build: {
      outDir: dotenvObj.BUILD_OUT_DIR || 'dist',
      rollupOptions: {
        output: {
          manualChunks(id) {
            if (id.includes('node_modules')) {
              return id.toString().split('node_modules/')[1].split('/')[0].toString()
            }
          },
        },
      },
    },
    plugins: [
      AutoImport({
        // 自动导入vue相关的Api
        imports: ["vue"],   // 也支持vue-router、axios等
        // 声明文件的存放位置
        dts: 'auto-imports.d.ts',
      }),
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/icons')],
        symbolId: 'icon-[dir]-[name]',
      }),
      vueJsx(),
      // 在正式打包的时候，可以把这三行代码放开
      // Components({
      //   resolvers: [ArcoResolver()],
      // }),
    ],
    css: {
      preprocessorOptions: {
        less: {
          additionalData: `@import "src/styles/variables.less";`,
          modifyVars: {
            'arcoblue-6': '#f85959',
            '--color-text-3': '#fff'
          },
          javascriptEnabled: true,
        },
      },
    },
    resolve: {
      alias: [
        {
          find: '@/',
          replacement: path.resolve(process.cwd(), 'src') + '/',
        },
        {
          find: 'vue',
          replacement: 'vue/dist/vue.esm-bundler.js', // 需要编译tmp
        }
      ],
    },
    server: {
      open: true,
      host: '0.0.0.0',
      port: 8222,
      proxy: {
        '^/api/': {
          // target: 'http://www.zz-ww.com:8222/',//测试
          // target: 'http://www.zz-ww.com:8223/',//邓
          // target: 'http://www.zz-ww.com:8224/',//刘
          target: 'http://120.196.185.227:7576/',//线
          // target:'http://192.168.110.72:8222/',//志文
          // target: 'http://192.168.110.23:8222/',//亨利
          // target: 'http://192.168.110.24:8222/',//
          changeOrigin: true,
        }

      }
    },
  }
})
